package com.lemon.smartsafety.view.pop;

import android.app.Activity;
import android.graphics.drawable.BitmapDrawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.PopupWindow;

import com.lemon.smartsafety.R;
import com.lemon.smartsafety.ui.adapter.pop.PopFireManageModeAdapter;
import com.lemon.smartsafety.view.list.MyListView;

import java.util.List;

/**
 * 项目名称：workspace
 * 类描述：
 * 创建人：Fargo
 * 创建时间：2016/8/8 15:17
 * 修改人：Fargo
 * 修改时间：2016/8/8 15:17
 * 修改备注：
 */
public class PopFireManage {

    public interface ClickSureBackInterface {
        public void callBackFunction(int  item);

    }


    public static void showPopupGeometry(final Activity activity, View view, final List<String> list,String strSelect, final ClickSureBackInterface clickSureBackInterface) {

        // 一个自定义的布局，作为显示的内容
        View contentView = LayoutInflater.from(activity).inflate(
                R.layout.pop_list, null);

        final PopupWindow popupWindow = new PopupWindow(contentView,
                ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT, true);
        popupWindow.setTouchable(true);
        popupWindow.setFocusable(true);
        popupWindow.setOutsideTouchable(true);

        activity.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE |
                WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);


        popupWindow.setBackgroundDrawable(new BitmapDrawable());


        final MyListView myListView = (MyListView) contentView.findViewById(R.id.listView);
        PopFireManageModeAdapter popFireManageModeAdapter=new PopFireManageModeAdapter(activity,list);
        popFireManageModeAdapter.setStrSelect(strSelect);
        myListView.setAdapter(popFireManageModeAdapter);
        myListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                clickSureBackInterface.callBackFunction(position);
                popupWindow.dismiss();
            }
        });


        // 设置好参数之后再show
        popupWindow.showAsDropDown(view);
    }






}
